package mapreduce;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import warningreportcount.ReportCount;

import java.io.IOException;

public class ReportCountMapper extends Mapper<LongWritable, Text, Text, ReportCount> {
    private Text k = new Text();
    private ReportCount reportCount = new ReportCount();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] fields = line.split("\t");
        String szVIN = fields[1];
        String error = fields[5];
        int count = Integer.valueOf(fields[4]);
        k.set(szVIN + "-" + error);
        reportCount.setCount(count);
        reportCount.setError(error);

        context.write(k, reportCount);
    }
}
